package cn.kooki.app.duobao.ui.Adapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.data.Bean.cart.CartInfo;
import cn.kooki.app.duobao.util.manager.AppManager;
import cn.kooki.app.duobao.util.manager.ShopCartManager;

/**
 * Created by xiong on 2015/12/21.
 */
public class OrderAdapter extends BaseAdapter {


    private Context context;

    public OrderAdapter(Context context) {
        this.context = context;

    }

    @Override
    public int getCount() {
        return ShopCartManager.getInstance().getCartsSize();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        CartInfo cartInfo = ShopCartManager.getInstance().getItemAtPostion(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_order, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.goodName.setText(cartInfo.title);
        String name = "<font color='red'>" + cartInfo.count + "</font>" + "人次";
        viewHolder.aside.setText(Html.fromHtml(name));
        return convertView;
    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'layout_order.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.aside)
        TextView aside;
        @Bind(R.id.good_name)
        TextView goodName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
